package com.itsitio.registeradmin.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itsitio.registeradmin.dao.UserRegistrationDao;
import com.itsitio.registeradmin.dto.UserRegistrationDTO;
import com.itsitio.registeradmin.dto.UserRegistrationStatisticDTO;
import com.itsitio.registeradmin.model.UserRegistration;
import com.itsitio.registeradmin.service.UserRegistrationSrv;

@Service
public class UserRegistrationSrvImpl implements UserRegistrationSrv {


	@Autowired
	private UserRegistrationDao userRegistrationDao;
	
	/* (non-Javadoc)
	 * @see com.itsitio.registeradmin.service.UserSrv#findAll()
	 */
	public List<UserRegistration> findAll() {
		return userRegistrationDao.obtenerTodos();
	}

	/* (non-Javadoc)
	 * @see com.itsitio.registeradmin.service.UserSrv#getEmployee(java.lang.Long)
	 */
	public UserRegistration get(Integer userRegId) {
		return userRegistrationDao.obtener(userRegId);
	}

	
	public List<UserRegistration> findUserRegistrationReq(Integer portalId, Integer countryId) {
		System.out.println("===== UserSrvImpl.findUserRegistrationReq(portalId="+portalId+", countryId="+countryId+")");
		List<UserRegistration> result = userRegistrationDao.findUserRegistrationReq(portalId, countryId );
		if (result !=null)
			System.out.println("===== UserSrvImpl.findUserRegistrationReq() result.size()="+result.size());
		else
			System.out.println("===== UserSrvImpl.findUserRegistrationReq() result is null");
		
		/*
		UserRegistration userRegistration = new UserRegistration();
		userRegistration.setAddress("Av. Acoyte 456");
		userRegistration.setCity("Rosario");
		userRegistration.setCompany("Molinos SA");
		userRegistration.setCountry("Argentina");
		userRegistration.setEmail("juan.tera@molinos.com.ar");
		userRegistration.setFirstName("Juan");
		userRegistration.setLastName("Tera");
		userRegistration.setPhone("(0341) 449-7771");
		userRegistration.setPortal("AMD");
		userRegistration.setRegistrationDate(new Date());
		userRegistration.setRegistrationState("Nueva");
		userRegistrationDao.guardar(userRegistration);
		*/
			
		return result;
	}

	public List<UserRegistrationDTO> findUserRegistrationReq(Integer portalId, Integer countryId, Date fromDate, 
			Date toDate, String firstName, String lastName, String email, String state){
		System.out.println("===== UserSrvImpl.findUserRegistrationReq(portalId="+portalId+", countryId="+countryId+", fromDate="+fromDate+", toDate="+toDate+")");

		List<UserRegistrationDTO> result = userRegistrationDao.findUserRegistrationReq(portalId, countryId, fromDate, toDate, firstName, lastName, email, state );
		if (result !=null)
			System.out.println("===== UserSrvImpl.findUserRegistrationReq() result.size()="+result.size());
		else
			System.out.println("===== UserSrvImpl.findUserRegistrationReq() result is null");
		
		/*
		UserRegistration userRegistration = new UserRegistration();
		userRegistration.setAddress("Av. Acoyte 456");
		userRegistration.setCity("Rosario");
		userRegistration.setCompany("Molinos SA");
		userRegistration.setCountry("Argentina");
		userRegistration.setEmail("juan.tera@molinos.com.ar");
		userRegistration.setFirstName("Juan");
		userRegistration.setLastName("Tera");
		userRegistration.setPhone("(0341) 449-7771");
		userRegistration.setPortal("AMD");
		userRegistration.setRegistrationDate(new Date());
		userRegistration.setRegistrationState("Nueva");
		userRegistrationDao.guardar(userRegistration);
		*/
			
		return result;

		
	}
	
	
	public List<UserRegistrationStatisticDTO> findUserRegistrationStatistic(Integer userId){

		System.out.println("===== UserSrvImpl.findUserRegistrationReq(userId="+userId+")");
		List<UserRegistrationStatisticDTO> result = userRegistrationDao.findUserRegistrationStatistic(userId);
		if (result !=null)
			System.out.println("===== UserSrvImpl.findUserRegistrationReq() result.size()="+result.size());
		else
			System.out.println("===== UserSrvImpl.findUserRegistrationReq() result is null");
		
		/*
		UserRegistration userRegistration = new UserRegistration();
		userRegistration.setAddress("Av. Acoyte 456");
		userRegistration.setCity("Rosario");
		userRegistration.setCompany("Molinos SA");
		userRegistration.setCountry("Argentina");
		userRegistration.setEmail("juan.tera@molinos.com.ar");
		userRegistration.setFirstName("Juan");
		userRegistration.setLastName("Tera");
		userRegistration.setPhone("(0341) 449-7771");
		userRegistration.setPortal("AMD");
		userRegistration.setRegistrationDate(new Date());
		userRegistration.setRegistrationState("Nueva");
		userRegistrationDao.guardar(userRegistration);
		*/
			
		return result;
		
	}

	@Override
	public void changeStatus(Integer idUserRegistration, String status, String comments) {
		UserRegistration userRegistration  = userRegistrationDao.obtener(idUserRegistration);
		userRegistration.setStatus(status); 
		userRegistration.setComments(comments);
		userRegistrationDao.guardar(userRegistration);
		
	}

	@Override
	public UserRegistration updateUserRegistrationStatus(Integer userRegId,
			String status) {
		UserRegistration userRegistration  = userRegistrationDao.obtener(userRegId);
		userRegistration.setStatus(status); 
		userRegistrationDao.guardar(userRegistration);
		return userRegistration;
	}
	
}
